package site.zhouinfo.gongjijin;

import org.joda.time.LocalDate;
import org.joda.time.Months;

/**
 * 计算公积金能贷款多少钱
 *
 * @author zhou
 * @create 2017-03-07 15:49
 * @email zhouinfo@qq.com
 */
public class CalculationGongJIJin {

    public static final double preTax = 3000;                       // 税前(元) (根据工资调整)
    public static final double highest = 60 * 10000;                // 个人(元) 最高贷款(极限)
    public static final double personalDepositRatio = 0.05;         // 个人(%) 缴存率 每个月份交的公积金占 税前 工资比例
    public static final double companyDepositRatio = 0.05;          // 公司(%) 缴存率
    public static int retiringAge = 60;                             // 退休年龄
    public static LocalDate birthday = new LocalDate(1993, 02, 10); // 出生 年月日
    public static LocalDate nowDate = new LocalDate(2017, 03, 07);  // 现在 年月日

    public static double personalDepositAmount = 0;                 // 个人 缴存额 每个月份交的公积金
    public static double companyDepositAmount = 0;                  // 公司 缴存额
    public static double cumulativePersonalDepositAmount = 0;       // 个人 累计缴存额
    public static double cumulativeCompanyDepositAmount = 0;        // 公司 累计缴存额
    public static double monthDepositAmount = 0;                    // 每月存额
    public static double allDepositAmount = 0;                      // 公积金 余额
    public static int age = 0;                                      // 年龄
    public static int retiringMonth = 0;                            // 距离退休还剩多少月份
    public static LocalDate retiringYear = birthday.plusYears(retiringAge);  // 退休 年月日
    public static LocalDate now = nowDate;                          //
    public static double LoanLimit = 0;                             // 贷款额度

    public static void main(String[] args) {
        Months months = Months.monthsBetween(nowDate, retiringYear);
        retiringMonth = months.getMonths();
        System.out.println("现在是 " + nowDate.toString() + " 需要工作到 " + retiringYear.toString() + "    共 " + retiringMonth + " 个月");
        System.out.println("计算公式 贷款额度=账户余额×8+月缴存额×到退休年龄月数");
        System.out.println("编号\t\t" + "日期\t\t\t\t" + "年后\t\t" + "工作月份\t\t" + "个人累计\t\t" + "公司累计\t\t" + "每月存款\t\t" + "累计公积金\t"
                + "贷款额度\t\t" + "账户余额×8" + "\t" + "月缴存额×到退休年龄月数");
        for (int i = 0; i < retiringMonth; i++) {
            personalDepositAmount = preTax * personalDepositRatio;
            cumulativePersonalDepositAmount = cumulativePersonalDepositAmount + personalDepositAmount;

            companyDepositAmount = preTax * companyDepositRatio;
            cumulativeCompanyDepositAmount = cumulativeCompanyDepositAmount + companyDepositAmount;

            monthDepositAmount = personalDepositAmount + companyDepositAmount;
            allDepositAmount += monthDepositAmount;

            LoanLimit = allDepositAmount * 8 + monthDepositAmount * (retiringMonth - i);

            System.out.println(i + "\t\t" + nowDate.toString() + "\t\t" + (i / 12) + "\t\t" + (retiringMonth - i) + "\t\t\t" + cumulativePersonalDepositAmount + "\t\t" + cumulativeCompanyDepositAmount
                    + "\t\t" + monthDepositAmount + "\t\t" + allDepositAmount + "\t\t" + (LoanLimit > highest ? highest : LoanLimit)
                    + "\t" + allDepositAmount * 8 + "\t\t" +
                    "" + monthDepositAmount * (retiringMonth - i));

            nowDate = nowDate.plusMonths(1);
            if (LoanLimit > highest) break;
        }
    }
}
